package web.dmt.dao.impl;

import java.sql.*;

import web.dmt.vo.Admin;

import web.dmt.dao.*;
import web.dmt.date.DATE;

public class Back_AdminImpl implements Back_AdminDAO{
	private Connection conn = null ;
	private PreparedStatement pstm = null ;
	java.util.Date d = null ;
	java.sql.Date de = null ;
	DATE date = new DATE() ;
	
	public Back_AdminImpl(Connection conn){
		this.conn = conn ;
	}
	
	public boolean delete(String chart,int id) throws Exception {
		boolean flag = false ;
		if(chart!=null&&id!=0&&!"".equals(chart.trim())){
			if("users".equals(chart)){
				String sql = "delete from users where uid="+id ;
				this.pstm = this.conn.prepareStatement(sql) ;
				if(this.pstm.executeUpdate()>0){
					flag = true ;
				}
			}
		}
		return flag ;
	}
	public Admin findLogin(String username,String pasword)throws Exception{
		Admin admin=null;
		String sql="select adid,username,password from admin where username=? and password=?";
		this.pstm=this.conn.prepareStatement(sql);
		this.pstm.setString(1,username);
		this.pstm.setString(2,pasword);
		ResultSet rs=this.pstm.executeQuery();
		while(rs.next()){
			admin=new Admin();
			admin.setAdid(rs.getInt(1));
			admin.setUsername(rs.getString(2));
			admin.setPasword(rs.getString(3));
		}
		return admin;
	}
	public Admin findById(Integer adid) throws Exception {
		Admin admin=null;
		String sql="select adid,adname,adpasword  where adid=?";
		this.pstm=this.conn.prepareStatement(sql);
		this.pstm.setInt(1,adid);
		ResultSet rs=this.pstm.executeQuery();
		while(rs.next()){
			admin=new Admin();
			admin.setAdid(rs.getInt(1));
			admin.setUsername(rs.getString(2));
			admin.setPasword(rs.getString(3));
		}
		return admin;
	}
}
